package com.jijs.soap;

import java.util.ArrayList;
import java.util.List;

import javax.jws.HandlerChain;
import javax.jws.WebService;

/**
 * 如果加targetNamespace，则接口也要加上
 * @author jjs
 *
 */
@WebService(endpointInterface = "com.jijs.soap.IMyService", targetNamespace="http://www.infcn.com.cn/")
@HandlerChain(file="com/jijs/soap/handler/handler-chain.xml")
//@SOAPBinding(style=Style.RPC)	//RPC方式
public class MyServiceImpl implements IMyService {

	private static List<User> users = new ArrayList<User>();

	public MyServiceImpl() {
		users.add(new User(1, "admin", "管理员", "123456"));
	}

	@Override
	public int add(int a, int b) {
		System.out.println(a + "+" + b + "=" + (a + b));
		return a + b;
	}

	@Override
	public User addUser(User user) {
		users.add(user);
		return user;
	}

	@Override
	public User login(String userName, String password) throws UserException{
		for (User user : users) {
			if (user.getUserName().equals(userName) && user.getPassword().equals(password)) {
				return user;
			}
		}
		throw new UserException("用户不存在！");
	}

	@Override
	public List<User> list() {
		return users;
	}

	@Override
	public List<User> listHeader(String authInfo) {
		System.out.println("authInfo:"+authInfo);
		return users;
	}

}
